/*
 * @Description:
 * @Author: Jevon
 * @Date: 2021-11-24 17:50:08
 */
export function addWheelEventListener(el, type, fn, capture) {
  const _eventCompat = function(event) {
    const type = event.type;
    if (type == 'DOMMouseScroll' || type == 'mousewheel') {
      event.delta = event.wheelDelta ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
    }
    if (event.srcElement && !event.target) {
      event.target = event.srcElement;
    }
    if (!event.preventDefault && event.returnValue !== undefined) {
      event.preventDefault = function() {
        event.returnValue = false;
      };
    }
    return event;
  };
  if (window.addEventListener) {
    if (type === 'mousewheel' && document.mozFullScreen !== undefined) {
      type = 'DOMMouseScroll';
    }
    el.addEventListener(
      type,
      function(event) {
        fn(_eventCompat(event));
      },
      capture || false
    );
  } else if (window.attachEvent) {
    el.attachEvent('on' + type, function(event) {
      event = event || window.event;
      fn.call(el, _eventCompat(event));
    });
  }
}
